#include <vector>
class Solution {
public:

	int LastRemaining_Solution(int n, int m) {
		vector<int> vt(n);
		vector<bool> check(n, false);
		for (int i = 0; i < n; ++i)
			vt[i] = i;
		int cur = 0;
		while (vt.size() != 1)
		{
			int del = (cur + m - 1) % vt.size();
			vt.erase(vt.begin() + del);
			cur = del;
		}
		return vt[0];
	}
};